package com.onluy.frameworkcloud.system;

import java.io.Serializable;
import java.util.List;

import com.alibaba.fastjson.JSON;

public class RespInfo  implements Serializable
{

    public RespInfo()
    {
    }

    public String getRespCode()
    {
        return respCode;
    }

    public void setRespCode(String respCode)
    {
        this.respCode = respCode;
    }

    public String getRespDesc()
    {
        return respDesc;
    }

    public void setRespDesc(String respDesc)
    {
        this.respDesc = respDesc;
    }

    public Object getData()
    {
        return data;
    }

    public Object getData(Class clazz)
    {
        if(data != null && !clazz.equals(data.getClass()))
            return JSON.parseObject(data.toString(), clazz);
        else
            return data;
    }

    public Object getList(Class beanClazz)
    {
        return getList(beanClazz, List.class);
    }

    public Object getList(Class beanClazz, Class listClazz)
    {
        if(data != null && !listClazz.equals(data.getClass()) && !beanClazz.equals(data.getClass()))
        {
            List list = JSON.parseArray(data.toString(), beanClazz);
            if(listClazz.equals(List.class) || listClazz.equals(List.class))
                return list;
            List nList = null;
            try
            {
                nList = (List)listClazz.newInstance();
            }
            catch(InstantiationException e)
            {
                e.printStackTrace();
            }
            catch(IllegalAccessException e)
            {
                e.printStackTrace();
            }
            nList.addAll(list);
            return nList;
        } else
        {
            return data;
        }
    }

    public void setData(Object data)
    {
        this.data = data;
    }

    public String getTime()
    {
        return time;
    }

    public void setTime(String time)
    {
        this.time = time;
    }

    private static final long serialVersionUID = 1L;
    private String respCode;
    private String respDesc;
    private String time;
    private Object data;
}
